package com.zghhost.codedemo.weight;

public class ChoujiangCeshi {
	public static void main(String[] args) {
		double jishu = 1000000;
		
		double n_toufang = 500;
		double n_shengyu = 300;
		double n_yugu = 10000;
		double n_yicanyu = 1000;
		
		double n_jiangpinrate = n_toufang * (jishu / n_toufang); 
		double n_shengyurate = n_shengyu * (jishu / n_toufang); 
		
		System.out.println(n_jiangpinrate);
		System.out.println(n_shengyurate);
		
//		System.out.println(doRamdon());
	}
	
	private static int doRamdon() {
		double[] ds = new double[] {1.0 , 50.0 , 4.0 , 15.0 , 10.0 , 20.0  };
		double sum = getSum(ds);
		double last = 0;
		for (int i = 0; i < ds.length; i++) {
			sum = sum- last;
			double random = Math.random();
			if (random <= ds[i] / sum) {
				return i;
			}
			last = ds[i];
		}
		
		return 5;
	}
 
	private static double getSum(double[] weight) {
		double sum = 0;
		for (double d : weight) {
			sum += d;
		}
		return sum;
	}
}
